#pragma once

#include "CoreMinimal.h"
#include "LRG_Node_ComponentBuckets.h"
#include "ReplicationGraph.h"
#include "Define/SpatialCoordinate.h"
#include "LRG_Node_GridCell.generated.h"

class ULineReplicationGraphComponent;
class ULRG_Node_ActorListFrequencyBuckets;

UCLASS()
class LINEREPLICATIONGRAPH_API ULRG_Node_GridCell : public UReplicationGraphNode_ActorList
{
	GENERATED_BODY()
	
	friend class ULRG_Node_GridSpatial;
public:
	ULRG_Node_GridCell();

	virtual FString GetDesc() override;
	virtual void GatherActorListsForConnection(const FConnectionGatherActorListParameters& Params) override;

	void AddActor_Dynamic(ULineReplicationGraphComponent* Component);
	void RemoveActor_Dynamic(ULineReplicationGraphComponent* Component);

	void AddActor_Static(ULineReplicationGraphComponent* Component);
	//UReplicationGraphNode_GridCell
	void AddStaticActor(const FNewReplicatedActorInfo& ActorInfo, FGlobalActorReplicationInfo& GlobalRepInfo, bool bParentNodeHandlesDormancyChange){}//TODO
	void RemoveStaticActor(const FNewReplicatedActorInfo& ActorInfo, FGlobalActorReplicationInfo& ActorRepInfo, bool bWasAddedAsDormantActor){}		//TODO
	UReplicationGraphNode_DormancyNode* GetDormancyNode() {return nullptr;}	//TODO
public:
	int32 GetCellId() const;
protected:
	virtual void InitializeCell(ULRG_Node_GridSpatial* Grid, int32 CoordX, int32 CoordY);
protected:
	FSpatialCoordinate Coordinate;

	UPROPERTY()
	TObjectPtr<ULRG_Node_ActorListFrequencyBuckets> DynamicActorListFrequencyBucketsNode;
protected:
	UPROPERTY()
	TArray<ULRG_Node_GridCell*> NeighborCells;	//相邻的格子
	UPROPERTY()
	int32 NeighborRange = 2;	//缓存的相邻格子的范围
	UPROPERTY()
	ULRG_Node_GridSpatial* OwnerGrid = nullptr;
	UPROPERTY()
	TObjectPtr<ULRG_Node_ComponentBuckets> ComponentBuckets;

	FString Describe;
};